import $ from 'jquery';

// <!-- auto generated navs start -->
const autoGenHeaderNavs = [];
const autoGenAsideNavs = [];
// <!-- auto generated navs end -->

const customHeaderNavs = [
  {
    text: '首页',
    to: '/',
    icon: 'home',
  },
  {
    text: '帮助',
    to: 'https://regan_jeff.gitee.io/jfinal-api/',
    icon: 'bangzhu',
    newWindow: true,
  },
];

const customAsideNavs = [
    {
        text: "主页",
        to: "/api/home",
        icon: 'home',
    }
]

// //调用后天接口生成路由
$.ajax({
    url : '/api/getMenuData',
    cache : false,
    async : false,
    type : "POST",
    success : function (result){
        JSON.parse(result).forEach((item) =>{
            let json = {
                text: item.menuName,
                to: item.href,
                icon: 'shezhi',
            }
            if (undefined != item.children && item.children.length >0) {
                let children = [];
                item.children.forEach((i) =>{
                    let child = {
                        text: i.menuName,
                        to: "/api"+(item.href == "/"?"":item.href) +"/"+i.href,
                    }
                    children.push(child);
                })
                json["children"] = children;
            }
            customAsideNavs.push(json);
        })
    }
});

const helpAsideNavs = [
    {
        text: "前言",
        to: "qianyan",
        icon: 'kongjian02',
    },
    {
        text: "入门",
        to: "rumeng",
        icon: 'beginnerguide',
    },
    {
        text: "功能菜单",
        to: "menu",
        icon: 'caidan',
    },
    {
        text: "Controller注释配置",
        to: "menu",
        icon: 'caidan1',
        isChild:true,
    },
    {
        text: "Method注释配置",
        to: "method",
        icon: 'Billingmethod',
        isChild:true,
    },
    {
        text: "postman",
        to: "postman",
        icon: 'post',
    },
];


function transform(navs) {
  // custom logical
  return [...navs];
}

export const headerNavs = transform([
  ...autoGenHeaderNavs,
  ...customHeaderNavs,
]);
export const asideNavs = transform([...autoGenAsideNavs, ...customAsideNavs]);

export const helpNavs = transform([...helpAsideNavs]);